package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.BaseCo;
import com.engineering.elink.common.ErrorType;
import com.engineering.elink.service.VideoCategoryService;
import com.engineering.elink.util.ResJsonUtil;

/**
 * 职业考证分类restful接口，请求转发及支持跨域
 */
@RestController
@CrossOrigin
@RequestMapping("/api/practice")
@Api(value="执业考证分类接口")
public class PracticeController {
	@Autowired
	private VideoCategoryService videoCategoryService;
	
	/**
	 * 获取培训视频一级分类
	 */
	@RequestMapping(value = "/getTopCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取执业考证一级分类接口")
	public Map<String, Object> getTopCategory() {
		//执业考证默认取为4的
		return ResJsonUtil.getMap(ErrorType.SUCCESS,videoCategoryService.getTopCategory(4));
	}
	
	/**
	 * 根据一级分类ID获取培训视频二级分类
	 */
	@RequestMapping(value = "/getSecondaryCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取执业考证二级分类接口")
	public Map<String, Object> getSecondaryCategory(@ApiParam(value = "一级分类 tcId", required = true) @RequestParam("tcId") int tcId,@ModelAttribute @Valid BaseCo co) {
		return ResJsonUtil.getMap(ErrorType.SUCCESS, videoCategoryService.getSecondaryCategory(tcId,co));
	}
	
	/**
	 * 根据二级分类ID获取三级分类
	 */
	@RequestMapping(value = "/getThirdCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取执业考证三级分类接口")
	public Map<String, Object> getThirdCategory(@ApiParam(value = "二级分类 scId", required = true) @RequestParam("scId") int scId) {
		return ResJsonUtil.getMap(ErrorType.SUCCESS,videoCategoryService.getThirdCategory(scId));
	}
}
